<template>
	<view>
		<cu-custom bgColor="bg-red" :isBack="true">		<block slot="backText"></block>
			<block slot="content">竞拍记录</block>
		</cu-custom>

		<view class=" overflow" v-if="detail">
			<block v-for="(product, i) in detail.product" :key="i">
				<view class="padding-sm solid-bottom padding-bottom-sm bg-white margin-lr margin-top">
					<view class="space-between ">
						<view class="cu-avatar xl bg-white">
							<image :src="product.product.picture" mode="aspectFill"></image>
						</view>
						<view class="w100 margin-left">
							<view class="text-overflow">{{product.product.name}}</view>
							<block v-if="product.win_member_id > 0">
								<view class="text-overflow text-gray">成交用户：{{product.winer.niakname}}</view>
								<view class="text-overflow text-gray">成交价：{{product.win_interval}}</view>
								<view class="text-overflow text-gray">成交时间：{{$common.timeFormat(product.win_time)}}</view>
							</block>
							<block v-else></block>
						</view>
					</view>
					<view class="space-between solid-top padding-top-sm margin-top-sm">
						<view>
							<text class="cu-btn bg-orange round sm" v-if="member.id==product.win_member_id" @tap="editAddress(product)">填写收货信息</text>
						</view>
						<view class="text-blue" @tap="goPage('/pages/shop/goods?id=' +product.product_id)">商品详情</view>
					</view>
				</view>
			</block>
		</view>


		<view class="cu-modal  " :class="addressModal?'show':''" @tap="addressModal = false">
			<view class="cu-dialog " @tap.stop="">
				<view class="bg-white overflow">
					<view class="text-right margin">
						<view class="action text-gray" @tap="addressModal = false">关闭</view>
					</view>
					<view class="cu-form-group">
						<view class="title">收货人手机号</view>
						<input placeholder="收货人手机号" name="input" class="text-right" v-model="formData.mobile"></input>
					</view>
					<view class="cu-form-group">
						<view class="title">收货人姓名</view>
						<input placeholder="收货人姓名" name="input" class="text-right" v-model="formData.name"></input>
					</view>
					<view class="cu-form-group align-start">
						<view class="title">收货地址</view>
					</view>
					<view class="cu-form-group bg-gray margin-lr-sm">
						<textarea maxlength="-1" placeholder="收货地址" class="text-left" v-model="formData.address"></textarea>
					</view>
					<view class="margin">
						<view class="cu-btn bg-blue w100 lg radius" @tap="onSubmit">确认</view>
					</view>
				</view>
			</view>
		</view>
		<view class="cu-load margin-center" :class="loading?'loading':'over'"></view>
	</view>
</template>

<script>
	import LiveView from '@/components/shop/LiveView.vue'
	export default {
		components: {
			LiveView
		},
		data() {
			return {
				id: 0,
				theme: this.$config.THEME(),
				member: null,
				detail: null,
				list: [],
				hasMore: true,
				loading: false,
				page: 1,
				addressModal: false,
				formData: {
					id:0,
					address: '',
					name: '',
					mobile: '',
				}
			}
		},
		onLoad(options) {
			if (options.id) this.id = options.id
			else this.$common.showErrorModal('参数有误')

			if (this.$common.loginAuth(true)) {
				this.$common.getMember().then((member) => {
					this.member = member
					this.getDetail()
				})
			}
		},
		methods: {
			getDetail() {
				uni.showLoading({
					title: '加载中...'
				})
				this.$http
					.get('marketing_auction_view', {
						id: this.id,
					})
					.then((response) => {
						uni.hideLoading()
						this.detail = response.data.data
					})
					.catch((response) => {
						uni.hideLoading()
					})
			},
			editAddress(item){
				this.formData.id = item.id
				this.formData.address = item.address
				this.formData.mobile = item.mobile
				this.formData.name = item.name
				this.addressModal = true
			},
			onSubmit() {
				uni.showLoading({
					title: '加载中...'
				})
				var formData = this.formData
				this.$http
					.put('marketing_auction_product_update', formData, {
						id: formData.id
					})
					.then((response) => {
						uni.hideLoading()
						this.$common.showSuccess('保存成功，请耐心等待')
					})
					.catch((response) => {
						uni.hideLoading()
					})

			},
		},
	}
</script>

<style>
</style>
